<template>
    <view>
        <view>
            <uni-search-bar placeholder="海量好房，一键搜索！" @confirm="search()" v-model="searchValue">
                <uni-icons slot="searchIcon" color="#999999" size="18" type="home" />
            </uni-search-bar>
        </view>

        <view>
            <view class="uni-flex uni-row" v-for="(j,index2) in sell" :key="j.houseId">
                <sellhouselist  v-bind:sell="j"></sellhouselist>
            </view>
        </view>
    </view>
</template>

<script>
    import {UniSearchBar} from "@dcloudio/uni-ui"
    import sellhouselist from "./sellhouselist.vue"
	// import HMfilterDropdown from '/src/pages/common/plus/HM-filterDropdown.vue';
	// import slFilter from '../../components/songlazy-sl-filter/sl-filter/sl-filter.vue'
    export default {
        name: "house_buy",
        data(){
            return{
                searchValue:'',
                sell:[]
            }
        },
        onLoad(option) {
			let data = option;
			// console.log(option.data)
			if(data.lon == undefined){				
				this.getHouse()
				this.$forceUpdate()
			}
			else{
				console.log('house_buy')
				console.log(data)		
				var params = {};
				
				let that = this;
				uni.request({
					url: 'https://restapi.amap.com/v3/geocode/regeo', //仅为示例，并非真实接口地址。
					data: {//参数
							location: data.lon+','+data.lat,
							key: 'c57eab66ecef610118acf5f0e13c1d82'
						},
					method:'GET',//请求方式  或GET，必须为大写
					success: res => {
						console.log('返回', res.data);
						let compo = res.data.regeocode.addressComponent;
						let str = compo.province.toString() + compo.city.toString()+
						compo.district.toString()+compo.township.toString();
						console.log(str);		
						that.getHousebyMap(str)
						that.$forceUpdate()
					}
					})
			}
        },
        methods:{
            search(){
            },
            getHouse(){
                this.$axios.post('getAllHouses')
                .then(res =>{
                this.house = res.data.allHouses
				this.getsell()
                })
            },
			getHousebyMap(add){
				let data = {address:add}
				this.$axios.post('getHousesByMap',this.qs.stringify(data))
				.then(res =>{
					// console.log(res.data.allHouses);
					this.house = res.data.allHouses;
					this.getsell();
					this.$forceUpdate();
				})
			},
            getsell(){
                this.$axios.post('getAllSells')
                .then(res =>{
                    this.selling = res.data.allSells
                    for(let j=0 ; j < this.house.length ; j++){
                        for(let k=0 ; k < this.selling.length ; k++){
                            if( this.house[j].houseId == this.selling[k].houseId){
                                let temporary = {}
                                temporary.houseId = this.house[j].houseId
                                temporary.sellHeading = this.selling[k].sellHeading
                                temporary.sellPrice = this.selling[k].sellPrice
                                temporary.houseArea = this.house[j].houseArea
                                temporary.houseSurfaceplot = this.house[j].houseSurfaceplot
                                temporary.houseDirection = this.house[j].houseDirection
                                temporary.houseEstate = this.house[j].houseEstate
                                this.sell.push(temporary)
                            }
                        }
                    }
					this.sell.reverse();
                    this.$forceUpdate()
                })
				.catch(e => {
					console.log(e)
				})
            }
        },
        components:{
            UniSearchBar,
            sellhouselist
            // 'HMfilterDropdown':HMfilterDropdown,
			// // slFilter
        }
    }
</script>

<style scoped>

</style>
